package com.etxxy.member.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.etxxy.common.exception.DataException;
import com.etxxy.common.exception.ServiceException;
import com.etxxy.member.domain.MemberRole;
import com.etxxy.member.mapper.MemberRoleMapper;
import com.etxxy.member.service.MemberRoleService;

@Service("memberRoleService")
public class MemberRoleServiceImpl implements MemberRoleService{
	
	private static final Logger logger = LoggerFactory.getLogger(MemberRoleServiceImpl.class);
	@Autowired
	private MemberRoleMapper memberRoleMapper;
	
	public MemberRole findMemberRoleById(String id) throws ServiceException, DataException {
		logger.info("查找角色的id={}",id);
		MemberRole memberRole = memberRoleMapper.selectByPrimaryKey(id);
		return memberRole;
	}

	@Override
	public int deleteMemberRoleById(String id) throws ServiceException, DataException {
		logger.info("删除用户角色的id={}",id);
		int result = memberRoleMapper.deleteByPrimaryKey(id);
		return result;
	}

	@Override
	public int updateMemberRoleById(MemberRole memberRole) throws ServiceException, DataException {
		logger.info("更新用户角色的memberRole={}",JSON.toJSONString(memberRole));
		int result = memberRoleMapper.updateByPrimaryKeySelective(memberRole);
		return result;
	}

	@Override
	public List<String> getRoleValuesByMemberId(String memberId) throws ServiceException, DataException {
		logger.info("得到用户角色值的memberId={}",memberId);
		List<String> roleValues = memberRoleMapper.getRoleValuesByMemberId(memberId);
		return roleValues;
	}

	@Override
	public List<MemberRole> getRolesByMemberId(String memberId) throws ServiceException, DataException {
		logger.info("得到用户角色的memberId={}",memberId);
		List<MemberRole> memberRoles = memberRoleMapper.getRolesByMemberId(memberId);
		return memberRoles;
	}
}
